<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>01_数据类型</title>
</head>
<body>
<script>
    //JS数据类型 = 原始类型 + 引用类型
    //原始类型:number string boolean undefined null
    //typeof用来推断数据类型
    var a = 1;
    var b = 3.14;
    console.log(a,typeof a,b,typeof b);//number
    var c = '你好';
    var d = "你好666";
    console.log(c,typeof c,d,typeof d);//string
    var e = true;
    var f = false;
    console.log(e,typeof e,f,typeof f);//boolean
    var g;
    console.log(g,typeof g);//undefined 'undefined'

    //引用类型 Object Array Function Number Boolean...
    let obj = {};
    console.log(obj,typeof obj); //{} 'object'
    let obj2 = {
        name:'张三',
        age:18
    };
    console.log(obj2,typeof obj2); //{} 'object'
    console.log(obj2.name,obj2.age);
    obj2.age = 20;
    console.log(obj2.age);
    //JS可以动态的往对象中新增属性
    obj2.like = '吃火锅';
    console.log(obj2); //{name: '张三', age: 20, like: '吃火锅'}
    obj2.play;
    console.log(obj2.play); //undefined

    //JS数组
    let arr = ['周一',3,4.6,true];
    console.log(arr);
    console.log(arr[0],arr[1],arr[2],arr[3]);
    console.log(arr[99]);//访问数组不存在的下标会得到undefined



    //Number()用于将参数转为数值类型，如果得不到数字结果，值为NaN(Not a Number)
    console.log(Number(true),typeof Number(true)); //1 'number'
    console.log(Number(false),typeof Number(false)); //0 'number'
    console.log(Number(3),typeof Number(3)); //3 'number'
    console.log(Number('3'),typeof Number('3')); //3 'number'
    console.log(Number('哈哈哈'),typeof Number('哈哈哈')); //NaN 'number'



</script>
</body>
</html>